package by.dkusch.aircompany.model.tables;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import by.dkusch.aircompany.model.tables.base.BaseEntity;

@Entity
public class Route extends BaseEntity<Long> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@NotNull
	@Size(max = 30)
	@Column
	private String code;

	@Size(max = 50)
	@Column
	private String name;

	@NotNull
	@ManyToOne(fetch = FetchType.LAZY, targetEntity = Airport.class)
	private Airport startPoint;

	@NotNull
	@ManyToOne(fetch = FetchType.LAZY, targetEntity = Airport.class)
	private Airport endPoint;

	@NotNull
	@Min(0)
	@Max(Integer.MAX_VALUE)
	@Column
	private Integer duration;

	@Size(max = 250)
	@Column
	private String description;

	@OneToMany(fetch = FetchType.LAZY, targetEntity = TimeTable.class, cascade = { CascadeType.ALL })
	@JoinColumn(name = "route_id")
	private Set<TimeTable> timeTable;

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Airport getStartPoint() {
		return startPoint;
	}

	public void setStartPoint(Airport startPoint) {
		this.startPoint = startPoint;
	}

	public Airport getEndPoint() {
		return endPoint;
	}

	public void setEndPoint(Airport endPoint) {
		this.endPoint = endPoint;
	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
